home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
c01lab4.zip
/
LRMRDR
/
LRM_CHAP.ZIP
/
CHAP13.DOC
< prev
next >
Wrap
Text File
|
1992-04-21
|
48KB
|
1,139 lines
> 13. Representation Clauses and Implementation-Dependent Features
This chapter describes representation clauses, certain
implementation-dependent features, and other features that are used in
system programming.
> 13.1 Representation Clauses
Representation clauses specify how the types of the language are to be
mapped onto the underlying machine. They can be provided to give more
efficient representation or to interface with features that are outside the
domain of the language (for example, peripheral hardware).
representation_clause ::=
type_representation_clause | address_clause
type_representation_clause ::= length_clause
| enumeration_representation_clause | record_representation_clause
A type representation clause applies either to a type or to a first named
subtype (that is, to a subtype declared by a type declaration, the base
type being therefore anonymous). Such a representation clause applies to
all objects that have this type or this first named subtype. At most one
enumeration or record representation clause is allowed for a given type:
an enumeration representation clause is only allowed for an enumeration
type; a record representation clause, only for a record type. (On the
other hand, more than one length clause can be provided for a given type;
moreover, both a length clause and an enumeration or record representation
clause can be provided.) A length clause is the only form of
representation clause allowed for a type derived from a parent type that
has (user-defined) derivable subprograms.
An address clause applies either to an object; to a subprogram, package,
or task unit; or to an entry. At most one address clause is allowed for
any of these entities.
A representation clause and the declaration of the entity to which the
clause applies must both occur immediately within the same declarative
part, package specification, or task specification; the declaration must
occur before the clause. In the absence of a representation clause for a
given declaration, a default representation of this declaration is
determined by the implementation. Such a default determination occurs no
later than the end of the immediately enclosing declarative part, package
specification, or task specification. For a declaration given in a
declarative part, this default determination occurs before any enclosed
body.
In the case of a type, certain occurrences of its name imply that the
representation of the type must already have been determined. Consequently
these occurrences force the default determination of any aspect of the
representation not already determined by a prior type representation
clause. This default determination is also forced by similar occurrences
of the name of a subtype of the type, or of the name of any type or subtype
that has subcomponents of the type. A forcing occurrence is any occurrence
other than in a type or subtype declaration, a subprogram specification, an
entry declaration, a deferred constant declaration, a pragma, or a
representation clause for the type itself. In any case, an occurrence
within an expression is always forcing.
A representation clause for a given entity must not appear after an
occurrence of the name of the entity if this occurrence forces a default
determination of representation for the entity.
Similar restrictions exist for address clauses. For an object, any
occurrence of its name (after the object declaration) is a forcing
occurrence. For a subprogram, package, task unit, or entry, any occurrence
of a representation attribute of such an entity is a forcing occurrence.
The effect of the elaboration of a representation clause is to define the
corresponding aspects of the representation.
The interpretation of some of the expressions that appear in representation
clauses is implementation-dependent, for example, expressions specifying
addresses. An implementation may limit its acceptance of representation
clauses to those that can be handled simply by the underlying hardware. If
a representation clause is accepted by an implementation, the compiler must
guarantee that the net effect of the program is not changed by the presence
of the clause, except for address clauses and for parts of the program that
interrogate representation attributes. If a program contains a
representation clause that is not accepted, the program is illegal. For
each implementation, the allowed representation clauses, and the
conventions used for implementation-dependent expressions, must be
documented in Appendix F of the reference manual.
Whereas a representation clause is used to impose certain characteristics
of the mapping of an entity onto the underlying machine, pragmas can be
used to provide an implementation with criteria for its selection of such a
mapping. The pragma PACK specifies that storage minimization should be the
main criterion when selecting the representation of a record or array type.
Its form is as follows:
pragma PACK(type_simple_name);
Packing means that gaps between the storage areas allocated to consecutive
components should be minimized. It need not, however, affect the mapping
of each component onto storage. This mapping can itself be influenced by a
pragma (or controlled by a representation clause) for the component or
component type. The position of a PACK pragma, and the restrictions on the
named type, are governed by the same rules as for a representation clause;
in particular, the pragma must appear before any use of a representation
attribute of the packed entity.
The pragma PACK is the only language-defined representation pragma.
Additional representation pragmas may be provided by an implementation;
these must be documented in Appendix F. (In contrast to representation
clauses, a pragma that is not accepted by the implementation is ignored.)
Note:
No representation clause is allowed for a generic formal type.
References: address clause 13.5, allow 1.6, body 3.9, component 3.3,
declaration 3.1, declarative part 3.9, default expression 3.2.1, deferred
constant declaration 7.4, derivable subprogram 3.4, derived type 3.4,
entity 3.1, entry 9.5, enumeration representation clause 13.3, expression
4.4, generic formal type 12.1.2, illegal 1.6, length clause 13.2, must 1.6,
name 4.1, object 3.2, occur immediately within 8.1, package 7, package
specification 7.1, parent type 3.4, pragma 2.8, record representation
clause 13.4, representation attribute 13.7.2 13.7.3, subcomponent 3.3,
subprogram 6, subtype 3.3, subtype declaration 3.3.2, task specification
9.1, task unit 9, type 3.3, type declaration 3.3.1
> 13.2 Length Clauses
A length clause specifies an amount of storage associated with a type.
length_clause ::= for attribute use simple_expression;
The expression must be of some numeric type and is evaluated during the
elaboration of the length clause (unless it is a static expression). The
prefix of the attribute must denote either a type or a first named subtype.
The prefix is called T in what follows. The only allowed attribute
designators in a length clause are SIZE, STORAGE_SIZE, and SMALL. The
effect of the length clause depends on the attribute designator:
(a) Size specification: T'SIZE
The expression must be a static expression of some integer type. The
value of the expression specifies an upper bound for the number of
bits to be allocated to objects of the type or first named subtype T.
The size specification must allow for enough storage space to
accommodate every allowable value of these objects. A size
specification for a composite type m